<template>
	<view class="page" :style="{'overflow':show?'hidden':''}">
		<view class="topbgimg">
			<image src="https://iflytts.oss-cn-qingdao.aliyuncs.com/website/img/webxzy/twoxze_7.png" mode="">
			</image>
		</view>
		<scroll-view scroll-y="true" class="scroll-Y" :key="1" v-if="!show">
			<view class="context">
				<view class="title">
					<text>不知道写什么？试试这个</text>
					<image style="width: 48rpx;height: 24rpx;margin: 0 4px;" src="/static/create/create_finger.png">
					</image>
					<text style="color: #3F96F7" @click="select('诛仙')">诛仙</text>
				</view>
				<view class="context-title">
					<text>小说类型</text>
					<text class="context-title-tip"></text>
				</view>
				<view class="context-tone">
					<view class="context-tone-item" v-for="(item,index) in toneList" :key="index"
						@click="changeTone(item,index)" :class="{'context-tone-item-select':index==toneIndex}">
						{{item.text}}
					</view>
				</view>
				<!--        -->
				<!--        -->
				<view class="context-title">
					<text>选择风格</text>
					<text class="context-title-tip"></text>
				</view>
				<view class="context-tone">
					<view class="context-tone-item" v-for="(item,index) in styleList" :key="index"
						@click="changeStyle(item,index)" :class="{'context-tone-item-select':index==styleIndex}">
						{{item.text}}
					</view>
				</view>
				<!--        -->
				<view class="context-tip">
					<view class="context-tip-left">
						<text>结果字数</text>
						<text class="context-tip-left-tip">*</text>
					</view>
					<!--            <view class="context-tip-right">至少包含10个字</view>-->
				</view>
				<view class="context-textarea" style="height: 80rpx">
					<textarea :value="message" placeholder="请输入字数(<= 1000)"
						placeholder-style="color:#999999;font-size:24rpx" :maxlength="20" @input="changeMessage"
						class="context-textarea-input" style="margin: -9rpx 0 0 0"></textarea>
					<!-- <view class="context-textarea-max">{{message.length}}/20</view> -->
				</view>
				<!--        -->
				<view class="context-tip">
					<view class="context-tip-left">
						<text>主题/关键词</text>
						<text class="context-tip-left-tip">*</text>
					</view>
					<!--            <view class="context-tip-right">至少包含50个字</view>-->
				</view>
				<view class="context-textarea">
					<textarea :value="writing" placeholder="请输入您想要的内容主题或者关键词。内容越详细越准确，生成的内容越好哦！"
						placeholder-style="color:#999999;font-size:24rpx" @input="changeValue" :maxlength="100"
						class="context-textarea-input"></textarea>
					<view class="context-textarea-max">{{writing.length}}/100</view>
				</view>
				<view class="button" @click="create"
					:style="{'background-color':(writing.length>0&&message.length>0)?'rgb(52, 116, 255)':'rgba(52, 116, 255,.3)'}">
					开始生成</view>
				<view style="height: 80rpx"></view>
			</view>
		</scroll-view>
		<view class="page-view" v-if="show" :key="2">
			<view class="answer">
				<view class="answer-value" style="font-size: 30rpx;">该结果由AI生成仅供参考</view>
				<view class="answer-textarea">
					<textarea :value="creativeResult" :maxlength="-1" class="answer-textarea-input"></textarea>
					<view class="answer-fontLength">共{{creativeResult.length}}字</view>
				</view>
			</view>
			<view class="tabbar">
				<view class="tabbar-item" @click="clickTab(item,index)" v-for="(item, index) in tabbarList"
					:key="index">
					<view>
						<image style="width: 38rpx;height: 38rpx;margin-top:8rpx" :src="item.src"></image>
					</view>
					<view style="margin-left:30rpx">{{item.text}}</view>
				</view>
			</view>
		</view>
		<!--  进度条  -->
	</view>
</template>

<script>
	import {
		wycUrl,
		sslbiz,
		wycUrlApi,
		apiMixUrlApi
	} from '@/api/assemb.js'
	export default {
		data() {
			return {
				scheduleShow: false,
				toneIndex: 0,
				toneList: [{
						text: '科幻/奇幻'
					},
					{
						text: '悬疑/推理'
					},
					{
						text: '爱情'
					},
					{
						text: '幽默'
					},
					{
						text: '历史/传记'
					},
					{
						text: '动作/战争'
					},
					{
						text: '幽默/喜剧'
					},
					{
						text: '青春/成长'
					},
					{
						text: '恐怖'
					},
					{
						text: '武侠'
					},
					{
						text: '军事'
					},
					{
						text: '耽美'
					},
				],
				styleIndex: 0,
				styleList: [{
						text: '简洁明了'
					},
					{
						text: '叙事复杂'
					},
					{
						text: '浪漫主义'
					},
					{
						text: '现实主义'
					},
					{
						text: '活泼诙谐'
					},
					{
						text: '异想天开'
					},
					{
						text: '古典主义'
					}
				],
				show: false,
				message: '',
				languageItem: '科幻/奇幻',
				toneItem: '',
				styleItem: '现实主义',
				writing: '',
				title: '',
				outline: '',
				answer: '猫咪眯着眼睛，舒服的坐在沙发上。格子图案的地板，全息\n' +
					'图，VR，3D感。猫咪眯着眼睛，舒服的坐在沙发上。格子\n' +
					'图案的地板，全息图，VR，3D感。',
				tabbarList: [

					{
						src: '/static/create/create_continue1.png',
						text: '重新生成'
					},
					{
						src: '/static/create/create_copy1.png',
						text: '复制文本'
					}
				],
				creativeResult: '',
				creativeResults: '',
				compareResults: '',
				originality: '',
				aiLevel: 0,
				width: 0,
				arrIndex: [],
				widthIndex: 0,
				schedule: 0,
				text: '创作中,请稍后',
				isVip: false
			}
		},
		onShow() {
			this.isVip = uni.getStorageSync('vipType').vipStatus == 1 ? true : false;
		},
		onLoad(option) {
			// this.isVip = option.isVip == 1 ? true : false
			// this.isVip = true;
			console.log("?? ~ file: customInput.vue:138 ~ onLoad ~ this.frequency:", this.frequency)
		},
		methods: {
			func() {
				uni.setStorageSync('frequency', 3)
			},
		
			// AI伪原创
			changeLanguage(item, index) {
				this.languageIndex = index
				this.languageItem = item.text
			},
			changeStyle(item, index) {
				this.styleIndex = index
				this.styleItem = item.text
			},
			changeTone(item, index) {
				this.toneIndex = index
				this.toneItem = item.text
			},
			select(e) {
				this.message = '500'
				this.writing = '仙侠，玄幻，虐恋，叶凡'
				this.styleIndex = 3
			},
			changeOutline(e) {
				this.outline = e.detail.value
			},
			changeMessage(e) {
				this.message = e.detail.value
			},
			changeTitle(e) {
				this.title = e.detail.value
			},
			changeValue(e) {
				this.writing = e.detail.value
			},
			async create() {

				if (!this.message) {
					uni.showToast({
						title: '请输入产品名称',
						icon: 'none',
						duration: 2000
					});
					return
				}
				if (!this.writing) {
					uni.showToast({
						title: '请输入产品特点',
						icon: 'none',
						duration: 2000
					});
					return
				}
				
			   if (uni.getStorageSync('frequency') > 0 || this.isVip) {
			   let params = {
			   	"promptId": 70,
			   	"conditions": [`${this.writing}`, `${this.message}`, `${this.toneItem}`, `${this.styleItem}`],
			   };
			   	let param = encodeURIComponent(JSON.stringify(params));
			   
			   	console.log(param)
			   	uni.navigateTo({
			   		url: '/pages_markMoney/newtitle/newtitle?param=' + param
			   	})
			   } else {
			   	uni.showToast({
			   		title: '请开通会员后使用',
			   		icon: 'none'
			   	})
			   }
			},
			clickTab(item, index) {
				if (index == 0) {
					this.show = false
				} else {
					let text = this.creativeResult
					// #ifdef H5
					let textarea = document.createElement("textarea")
					textarea.value = text
					textarea.readOnly = "readOnly"
					document.body.appendChild(textarea)
					textarea.select() // 选中文本内容
					textarea.setSelectionRange(0, text.length)
					uni.showToast({ //提示
						title: '复制成功',
						icon: 'success'
					})
					document.execCommand("copy")
					textarea.remove()
					// #endif
					// #ifndef H5
					uni.setClipboardData({
						data: text, //要被复制的内容
						success: () => { //复制成功的回调函数
							uni.showToast({ //提示
								title: `复制成功`,
								icon: 'success'
							})
						}
					}, true);
					// #endif

				}
			},
		},
	}
</script>
<style lang="less">
	.page {
		width: 100%;
		height: calc(100vh);
		background: #F7FBFF;
		// background-size: 100% 100%;
		// background-repeat: no-repeat;
		// background-image: url("https://iflytts.oss-cn-qingdao.aliyuncs.com/website/img/aixz/create/bann.png");
	}

	.topbgimg {
		position: absolute;
		width: 100%;
		height: 230rpx;
		top: 0;
		left: 0;
		z-index: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.scroll-Y {
		width: 100%;
		height: 100%;
		background: rgba(255, 255, 255, 0.35);
	}

	.page-view {
		width: 100%;
		height: 100%;
	}

	.title {
		width: 120%;
		height: 80rpx;
		margin: 0 0 0 -20px;
		box-sizing: border-box;
		padding: 0rpx 40rpx;
		display: flex;
		align-items: center;
		//   background-color: #F7F7F7;
		// background-color: rgba(211, 238, 255, 0.5);
		font-size: 24rpx;
		color: #666666;
	}

	.context {
		width: 90%;
		margin: 0rpx auto;

		.context-tone {
			width: 100%;
			display: flex;
			flex-wrap: wrap;

			.context-tone-item {
				width: 18%;
				padding: 12rpx 14rpx;
				// background-color: #F7F7F7;
				border: 1px solid #fff;
				border-radius: 24rpx;
				font-size: 22rpx;
				//   margin-left: 15rpx;
				//   margin-right: 30rpx;
				//   margin-bottom: 30rpx;
				margin: 5px 0 0 8.3px;
				color: #333333;
				text-align: center;
				background: linear-gradient(315deg, #F1F5FF 18%, #ECF2FE 81%);
			}

			.context-tone-item-select {
				//   background-color: #4BB591;
				background: #4B85FF;
				color: #fff;
			}
		}

		.context-tip {
			width: 100%;
			height: 90rpx;
			margin-top: 10px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.context-tip-left {
				font-size: 30rpx;
				color: #333333;
				display: flex;
				align-items: center;

				/deep/.context-tip-left-tip span {
					color: red;
					margin-left: 6rpx;
					vertical-align: sub;
				}
			}

			.context-tip-right {
				color: #999999;
				font-size: 24rpx;
			}
		}

		.context-title {
			width: 100%;
			height: 90rpx;
			font-size: 30rpx;
			color: #333333;
			margin-top: 10px;
			display: flex;
			align-items: center;

			/deep/.context-title-tip span {
				color: red;
				margin-left: 6rpx;
				vertical-align: sub;
			}
		}

		.context-textarea {
			width: 100%;
			height: 240rpx;
			background-image: url(https://iflytts.oss-cn-qingdao.aliyuncs.com/website/img/webxzy/twoxze_6.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			border-radius: 24rpx;
			position: relative;

			.context-textarea-input {
				width: 100%;
				height: 100%;
				box-sizing: border-box;
				padding: 22rpx 30rpx 0 30rpx;
				color: #333333;
				font-size: 28rpx;
			}

			.context-textarea-max {
				position: absolute;
				right: 40rpx;
				bottom: 20rpx;
				color: #999999;
			}
		}

		.button {
			width: 90%;
			height: 90rpx;
			background-color: rgba(52, 116, 255, 0.3);
			border-radius: 60rpx;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 30rpx;
			margin: 40rpx auto 30rpx;
		}
	}

	.btn {
		display: flex;
		position: fixed;
		flex-direction: row;
		// background-color: rgba(211, 238, 255, 1);
		border-radius: 25px 25px 0 0;
		width: 100%;
		bottom: 0px;
		z-index: 99;
		margin-left: -20px;
	}

	.placeholder {
		height: 50%;
		padding-bottom: 200rpx;
	}

	.answer {
		width: 90%;
		margin: 0px auto;
		height: 90%;

		.answer-fontLength {
			width: 100%;
			height: 60rpx;
			color: #999999;
			font-size: 30rpx;
			// display: flex;
			// align-items: center;
			//padding-left: 520rpx;
			position: absolute;
			left: 76%;
		}

		.answer-value {
			width: 100%;
			height: 100rpx;
			color: #333333;
			font-size: 44rpx;
			line-height: 100rpx;
			// display: flex;
			// align-items: center;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.answer-textarea {
			position: relative;
			width: 100%;
			height: 50%;
			// background-color: #F7F7F7;
			border: 1px solid #3f96f7;
			border-radius: 24rpx;

			.answer-textarea-input {
				width: 100%;
				height: 92%;
				box-sizing: border-box;
				padding: 30rpx 30rpx 20rpx;
				color: #333333;
				font-size: 28rpx;
			}
		}
	}

	.tabbar {
		width: 100%;
		//   height: 10%;
		//   background-color: #fff;
		display: flex;
		box-sizing: border-box;
		justify-content: center;

		//   border-top: 1rpx solid #e5dbdb;
		.tabbar-item {
			width: 33.33%;
			height: 68.84rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			// flex-direction: column;
			font-family: PingFang SC;
			padding: 0 40rpx;
			font-weight: 500;
			color: #ffffff;
			line-height: 36rpx;
			font-size: 24rpx;
			border: solid 2rpx;
			margin: 0 12rpx;
			background: #3474ff;
			border-radius: 34rpx;
		}
	}

	/deep/::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}

	.schedule-page {
		width: 100%;
		height: 100vh;
		position: fixed;
		background-color: rgba(128, 126, 126, 0.8);
		top: 0px;
		left: 0px;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 200;
	}

	.schedule-box {
		width: 62%;
		background-color: #fff;
		border-radius: 15rpx;
	}

	.schedule-text {
		text-align: center;
		line-height: 120rpx;
	}

	.schedule {
		width: 100%;
		height: 20rpx;
		margin: 20rpx 0rpx;
	}

	.schedule-number {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #2979ff;
	}

	.lineBox {
		width: 90%;
		display: flex;
		justify-content: space-around;
		margin: 0px auto;
		height: 12rpx;
		border-radius: 24rpx;
		overflow: hidden;
	}

	.lineAnimation {
		height: 100%;
		background-color: #bbb9b9;
	}

	.lineAnimation-children {
		height: 100%;
		transition: all 0.5s;
		background-color: #2979ff;
	}

	.baifenbizdy {
		color: skyblue;
		font-size: 22px;
		align-items: center;
		justify-content: center;
		display: flex;
		margin-top: 7%;
	}

	.isshow {
		background-color: #fff;
		border-radius: 10px;
		width: 90%;
		height: 190px;
		left: 5%;
		position: relative;
		top: -70%;
		font-size: 50px;
		z-index: 10086;
		color: #1890ff;
		padding: 40px 0 0 0;
	}

	.box {
		width: 880px;
		background: #ffffff;
		position: relative;
		// height: 640px;
	}

	.textzdy {
		display: flex;
		font-size: 22px;
		margin: auto;
		color: grey;
		align-items: center;
		justify-content: center;
		padding-top: 2%;
	}

	.container {
		width: 90%;
		height: 7px;
		background-color: #fafafc;
		border-radius: 15px;
		margin-left: 5%;
		margin-top: 8%;
	}

	/* 内部加载部分样式 */
	.contentzdy {
		width: 100%;
		height: 7px;
		border-radius: 15px;
		background-color: #1890ff;
		text-align: center;
		line-height: 10px;
	}

	.jindu {
		margin-top: 1px;
	}
</style>